<template>
	<view class="p_bg_all">
		<view class="p_margin_t_32">
			<view class="form_list">
				<view class="form_label">抬头</view>
				<input placeholder="输入抬头" placeholder-class="p_font_28 p_color_b2" class="p_font_28 p_flex_2"
					v-model="formData.name" />
			</view>
			<view class="form_list">
				<view class="form_label">税号</view>
				<input type="number" placeholder="输入纳税人识别号" placeholder-class="p_font_28 p_color_b2"
					class="p_font_28 p_flex_2" v-model="formData.duty_paragraph" />
			</view>
			<view class="form_list">
				<view class="form_label">注册地址</view>
				<textarea placeholder="输入注册地址" placeholder-class="p_font_28 p_color_b2" class="p_font_28 p_flex_2"
					v-model="formData.company_address" style="height: 106rpx;"></textarea>
			</view>
			<view class="form_list">
				<view class="form_label">开户行</view>
				<input placeholder="输入开户银行" placeholder-class="p_font_28 p_color_b2" class="p_font_28 p_flex_2"
					v-model="formData.bank" />
			</view>
			<view class="form_list">
				<view class="form_label">银行账号</view>
				<input type="number" placeholder="输入银行账号" placeholder-class="p_font_28 p_color_b2"
					class="p_font_28 p_flex_2" v-model="formData.bank_account" />
			</view>
		</view>
		<view class="p_btn" @click="getSubmit">
			<view>保存</view>
		</view>
		<view class="p_del_btn" v-if="formData.id">
			<view @click="detelMsg = true">删除</view>
		</view>
		<!--  -->
		<tips messages="是否删除该抬头？" confirmText="确定" cancelText="再想想" :tipsShow="detelMsg"
			@getDialogCancel="detelMsg = false" @getDialogConfirm="getDetel"></tips>
	</view>
</template>

<script>
	import tips from '../../components/tips.vue';

	export default {
		components: {
			tips
		},
		data() {
			return {
				formData: {
					name: '',
					duty_paragraph: '',
					company_address: '',
					bank: '',
					bank_account: ''
				},
				detelMsg: false,
			}
		},
		onLoad(e) {
			uni.setNavigationBarTitle({
				title: e.id ? '编辑抬头' : '添加抬头'
			});

			if (e.id) {
				this.getDetail(e.id);
			}
		},
		methods: {
			getDetail(id) {
				this.$http.post(this.$api.lookUpDetail, {
					id
				}).then(res => {
					this.formData = {
						id: res.data.id,
						name: res.data.name,
						duty_paragraph: res.data.duty_paragraph,
						company_address: res.data.company_address,
						bank: res.data.bank,
						bank_account: res.data.bank_account
					}
				})
			},
			getSubmit() {
				if (!this.formData.name) return getApp().getMsg('请输入抬头');
				if (!this.formData.duty_paragraph) return getApp().getMsg('请输入纳税人识别号');
				if (!this.formData.company_address) return getApp().getMsg('请输入注册地址');
				if (!this.formData.bank) return getApp().getMsg('请输入开户银行');
				if (!this.formData.bank_account) return getApp().getMsg('请输入银行账号');

				if (!this.formData.id) {
					this.$http.post(this.$api.setLookUp, this.formData).then(res => {
						getApp().getMsg('抬头添加成功', 'success');
						getApp().getBack();
						uni.setStorageSync('riseDataUpdate', true);
					})
				} else {
					this.$http.post(this.$api.lookUpEdit, this.formData).then(res => {
						getApp().getMsg('抬头修改成功', 'success');
						getApp().getBack();
						uni.setStorageSync('riseDataUpdate', true);
					})
				}
			},
			getDetel() {
				this.$http.post(this.$api.lookUpDel, {
					id: this.formData.id
				}).then(res => {
					getApp().getMsg('抬头已删除');
					getApp().getBack();
					uni.setStorageSync('riseDataUpdate', true);
				})
			}
		}
	}
</script>

<style lang="less">
</style>
